import 'package:erp/data/api/process_api.dart';
import 'package:erp/data/model/page.dart';
import 'package:erp/data/model/process_type.dart';
import 'package:erp/routes/app_pages.dart';
import 'package:erp/widgets/page_list/page_list_control.dart';
import 'package:get/get.dart';

class ProcessApplyController extends PageListControl<ProcessType> {
  @override
  Future<PageData<ProcessType>> loadPageData({required int pageIndex}) async {
    var data = await ProcessApi.queryFlowTemplate();
    List<ProcessType> list = data.map<ProcessType>((m) => ProcessType.fromJson(m)).toList();
    list.removeWhere((element) => element.typeCode != "SALE_PROJECT");
    PageData<ProcessType> pageData = PageData(records: list, size: 10);
    return pageData;
  }

  @override
  void onInit() {
    super.onInit();
  }

  // 查看流程图
  void seeFlowChart(ProcessType processType) async {
    String typeCode = processType.typeCode;
    var data = await ProcessApi.queryFlowChart(typeCode);
    Get.toNamed(Routes.FLOW_CHART, arguments: {"data": data});
  }

  void apply(ProcessType item) async {
    Get.toNamed(Routes.SALE_PROJECT_APPLY, arguments: {'processType': item});
  }
}
